/*
 * @Author: RYPY
 * @Date: 2021-03-18 00:00:15
 * @LastEditors: RYPY
 * @LastEditTime: 2021-03-18 00:29:44
 */
const express=require("express");
const DB=require("../until/DB");
const {Msg,serverPath}=require("../until/config");
const router=express.Router();
//课程的详细信息
router.get("/courseinfo/:id",async (req,res,next)=>{
   let {id='1beec178-4b02-40fb-9d1c-8aa61cd4a097'}=req.params; 
   let sql=`SELECT c.cid,title,price,concat('${serverPath}/course_img/',image_src) image_src,type_name,area_name,grade_name,subject_name,t.tid,realname,t.intro,concat('${serverPath}/avatar/',head_photo_url)head_photo_url,count(*) num from e_course c INNER JOIN e_teacher t ON c.tid=t.tid JOIN e_order o ON o.cid=c.cid WHERE c.cid='${id}'`;
   let [err,result]=await DB.query(sql);

   if(!err){
        let videoSQL=`SELECT id vid,vnum,concat('${serverPath}/course_video/',video_src) video_src,video_title from e_video where cid='${id}'`;
        let [err1,result1]=await DB.query(videoSQL);
        if(!err1){
            result[0].videos=result1;
            res.send(Msg(200,"ok",result[0]));
        }else{
            next("请稍后再试！");
        }
   }else{
       next("请稍后再试！");
   }
});



module.exports=router;